//
//  MYShopSearchScreenCollViewCell.m
//  MuYing
//
//  Created by tbb on 2019/7/26.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYShopSearchScreenCollViewCell.h"
#define selectTableViewW (kYQPScreenWidth * (296.0/375))
#define kcollViewCellW ((selectTableViewW-62) / 3.0)
@interface MYShopSearchScreenCollViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView * collView;

@property (strong, nonatomic) NSMutableArray *attrValueArray;

@property (strong, nonatomic) NSMutableArray *attrIdsArray;

@property (strong, nonatomic) NSMutableArray *subBrandIds;

@property (strong, nonatomic) NSMutableArray *brandIds;

@property (strong, nonatomic) NSMutableDictionary *dic;
@end

@implementation MYShopSearchScreenCollViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.attrValueArray = NSMutableArray.new;
        self.attrIdsArray = NSMutableArray.new;

        self.brandIds = NSMutableArray.new;

        self.subBrandIds = NSMutableArray.new;
        
        self.dic = NSMutableDictionary.new;

        [self.contentView addSubview:self.collView];
        [self.collView mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.edges.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.right.mas_equalTo(-12);
            make.left.mas_equalTo(12);
        }];
    }
    return self;
}

- (void)setModel:(YQPGoodAttrValueModel *)model
{
    [self.attrValueArray removeAllObjects];
    _model = model;
    [self.attrValueArray addObjectsFromArray:model.attrValueList];
    [self.collView reloadData];
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

#pragma mark -- <UICollectionViewDelegate,UICollectionViewDataSource>
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.attrValueArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    YQPAttrValueListModel *model = self.attrValueArray[indexPath.row];
    MYShopSearchScreenSpecificationsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MYShopSearchScreenSpecificationsCell" forIndexPath:indexPath];
    cell.titleLb.text = model.valueName;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(kcollViewCellW,38);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 12.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 19.0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YQPAttrValueListModel *model = self.attrValueArray[indexPath.row];

    model.isSelected = !model.isSelected;

//    if (model.isSelected) {
//        cell.contentView.backgroundColor = kAPPThemeColor;
//        [self.attrIdsArray addObject:model.attrId];
//    }else{
//        cell.contentView.backgroundColor = HexColorA(0x000000, 0.03) ;
//    }
//    [self.collView reloadData];
    if ([self.delegate respondsToSelector:@selector(didSelectGoodItemModel:attrValueModel:)]) {
        [self.delegate didSelectGoodItemModel:self.model attrValueModel:model];
    }
}

#pragma mark -- <UICollectionViewDelegate,UICollectionViewDataSource> end


#pragma makr --lazy
-(UICollectionView *)collView {
    if (!_collView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collView.backgroundColor = UIColor.whiteColor;
        _collView.delegate = self;
        _collView.dataSource = self;
        _collView.showsVerticalScrollIndicator = NO;
        _collView.bounces = NO;
        [_collView registerNib:[UINib nibWithNibName:@"MYShopSearchScreenSpecificationsCell" bundle:nil] forCellWithReuseIdentifier:@"MYShopSearchScreenSpecificationsCell"];
    }
    return _collView;
}
#pragma makr --lazy end

//#pragma mark - hit-test
//- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//    UIView *view = [super hitTest:point withEvent:event];
//
//    return self.collView;
//}
@end
